package com.liwei.lwmail.order.controller;

import com.liwei.lwmail.order.entity.OrderEntity;
import com.liwei.lwmail.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg/{num}")
    public String sendMsg(@PathVariable("num") Integer num){
        for (int i = 0;i < num;i ++){
            if (i%2==0){
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(1L);
                entity.setName("李伟-"+i);
                entity.setCreateTime(new Date());
                rabbitTemplate.convertAndSend("exchange.direct","atguigu",entity, new CorrelationData(UUID.randomUUID().toString()));
            }else {
                OrderEntity entity = new OrderEntity();
                entity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("exchange.direct","atguigu",entity, new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }
}
